//一般直接写在一个js文件中
layui.use(['element','form','layer','laytpl','laydate'],function () {
    var form = layui.form,
    layer = layui.layer,
        laytpl = layui.laytpl,
        laydate = layui.laydate;
    calcMonery(true);
    laydate.render({
        elem: '#endTime' //指定元素
    });


    //添加收费项目
    $("#addRow").on('click',function(){
        var getTpl=document.getElementById('qtsf').innerHTML;
        var $itemsTbody = $("#items_tbody");
        laytpl(getTpl).render({}, function(html){
            $itemsTbody.append( html);
        });
    });
});

//删除其它收费项目
function delRow(that) {
    $(that).closest('tr').remove();
    calcMonery();
}

//计算费用
function calcMonery(flag) {
    var $cost = $(".cost");
    var total_cost = 0; //服务项目总费用
    if($cost.size() > 0){
        $cost.each(function(){
            var $recordsId = $(this).closest('tr').find(".recordsId");
            if($recordsId.prop("checked")){
                var cost = $(this).text();
                total_cost += Number(cost);
            }
        });
    }
    var $monery = $(".monery");
    var total_monery = 0; //其它收费项目总费用
    if($monery.size() > 0){
        $monery.each(function(){
            var monery = $(this).val();
            if(monery){
                total_monery += Number(monery);
            }
        });
    }

    var amount = total_cost + total_monery; // 总收费金额
    if(!flag){
        $("#amount").val(amount);
    }
    $("#qtze").val(total_monery);
    $("#fwze").val(total_cost);


}